package me.lc.superDown.sprite.tools;

import me.lc.superDown.core.GameManager;
import me.lc.superDown.core.GameSystem;
import me.lc.superDown.sprite.GameTool;
import me.lc.superDown.util.AudioHelper;

import com.wiyun.engine.actions.Action.Callback;
import com.wiyun.engine.actions.Animate;
import com.wiyun.engine.actions.FadeTo;
import com.wiyun.engine.actions.RepeatForever;
import com.wiyun.engine.actions.ScaleTo;
import com.wiyun.engine.actions.Spawn;
import com.wiyun.engine.nodes.Animation;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.types.WYRect;

public class SpeedDownTool extends GameTool {

	static float widthHeight = GameSystem.tex_speed_down.getWidth() / 2;

	@Override
	protected void createToolSprite() {
		toolSprite = Sprite.make(GameSystem.tex_speed_down, frameAt(0));
		Animation animation = new Animation(0);
		animation.addFrame(0.3f, frameAt(0), frameAt(1));
		RepeatForever forever = RepeatForever.make(Animate.make(animation));
		forever.autoRelease();
		toolSprite.runAction(forever);
	}

	public static WYRect frameAt(int i) {
		return WYRect.make(widthHeight * i, 0, widthHeight, widthHeight);
	}

	@Override
	public float getToolWidth() {
		return widthHeight;
	}

	@Override
	public float getToolHeight() {
		return widthHeight;
	}

	@Override
	public synchronized void hitTool() {
		// 减速10s
		if (!isHited) {
			isHited = true;
			AudioHelper.speedTool();
			// ScaleTo scale = (ScaleTo) ScaleTo.make(0.3f, 1.5f, 0.6f)
			// .autoRelease();
			// FadeTo fadeTo = (FadeTo) FadeTo.make(0.5f, 255, 0).autoRelease();
			// Spawn spawn = (Spawn) Spawn.make(fadeTo, scale).autoRelease();
			// toolSprite.runAction(spawn);
			toolSprite.setVisible(false);
			Thread t = new Thread() {
				@Override
				public void run() {
					GameManager.instance.hitSpeedDownTool();
				}
			};
			t.start();

		}
	}
}
